package com.fxwater.websocket.util;

import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Component;

/**
 * @Description:
 * @Author: 王明朝
 * @Date: 2019/8/17 13:03
 */
@Component
public class SpringBeanFinder implements ApplicationContextAware {

    private static ApplicationContext applicationContext;

    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        SpringBeanFinder.applicationContext = applicationContext;
    }

    public static <T>T findBean(Class<? extends T> clazz){
        return applicationContext.getBean(clazz);
    }

    public static <T>T findBean(String beanName){
        return (T) applicationContext.getBean(beanName);
    }
}
